home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v17n05 / dflat.592 < prev    next >
Encoding:
Text File  |  1992-03-30  |  20.6 KB  |  713 lines

  1. _C PROGRAMMING COLUMN_
  2. by Al Stevens
  3.  
  4.  
  5. [LISTING ONE]
  6.  
  7. /* ------------- applicat.c ------------- */
  8.  
  9. #include "dflat.h"
  10.  
  11. static int ScreenHeight;
  12. static BOOL AltDown = FALSE;
  13.  
  14. extern DBOX Display;
  15. extern DBOX Windows;
  16.  
  17. #ifdef INCLUDE_LOGGING
  18. extern DBOX Log;
  19. #endif
  20.  
  21. #ifdef INCLUDE_SHELLDOS
  22. static void ShellDOS(WINDOW);
  23. #endif
  24. static void CreateMenu(WINDOW);
  25. static void CreateStatusBar(WINDOW);
  26. static void SelectColors(WINDOW);
  27. static void SetScreenHeight(int);
  28. static void SelectLines(WINDOW);
  29.  
  30. #ifdef INCLUDE_WINDOWOPTIONS
  31. static void SelectTexture(void);
  32. static void SelectBorder(WINDOW);
  33. static void SelectTitle(WINDOW);
  34. static void SelectStatusBar(WINDOW);
  35. #endif
  36.  
  37. #ifdef INCLUDE_MULTI_WINDOWS
  38. static void CloseAll(WINDOW, int);
  39. static void MoreWindows(WINDOW);
  40. static void ChooseWindow(WINDOW, int);
  41. static int WindowSel;
  42. static WINDOW oldFocus;
  43. static char *Menus[9] = {
  44.     "~1.                      ",
  45.     "~2.                      ",
  46.     "~3.                      ",
  47.     "~4.                      ",
  48.     "~5.                      ",
  49.     "~6.                      ",
  50.     "~7.                      ",
  51.     "~8.                      ",
  52.     "~9.                      "
  53. };
  54. #endif
  55.  
  56. /* --------------- CREATE_WINDOW Message -------------- */
  57. static int CreateWindowMsg(WINDOW wnd)
  58. {
  59.     int rtn;
  60.     static BOOL DisplayModified = FALSE;
  61.     ScreenHeight = SCREENHEIGHT;
  62.     if (!isVGA() && !DisplayModified)    {
  63.         /* ---- modify Display Dialog Box for EGA, CGA ---- */
  64.         CTLWINDOW *ct, *ct1;
  65.         int i;
  66.         ct = FindCommand(&Display, ID_OK, BUTTON);
  67.         if (isEGA())
  68.             ct1 = FindCommand(&Display,ID_50LINES,RADIOBUTTON);
  69.         else    {
  70.             CTLWINDOW *ct2;
  71.             ct2 = FindCommand(&Display,ID_COLOR,RADIOBUTTON)-1;
  72.             ct2->dwnd.w++;
  73.             for (i = 0; i < 7; i++)
  74.                 (ct2+i)->dwnd.x += 8;
  75.             ct1 = FindCommand(&Display,ID_25LINES,RADIOBUTTON)-1;
  76.         }
  77.         for (i = 0; i < 4; i++)
  78.             *ct1++ = *ct++;
  79.         DisplayModified = TRUE;
  80.     }
  81. #ifdef INCLUDE_WINDOWOPTIONS
  82.     if (cfg.Border)
  83.         SetCheckBox(&Display, ID_BORDER);
  84.     if (cfg.Title)
  85.         SetCheckBox(&Display, ID_TITLE);
  86.     if (cfg.StatusBar)
  87.         SetCheckBox(&Display, ID_STATUSBAR);
  88.     if (cfg.Texture)
  89.         SetCheckBox(&Display, ID_TEXTURE);
  90. #endif
  91.     if (cfg.mono == 1)
  92.         PushRadioButton(&Display, ID_MONO);
  93.     else if (cfg.mono == 2)
  94.         PushRadioButton(&Display, ID_REVERSE);
  95.     else
  96.         PushRadioButton(&Display, ID_COLOR);
  97.     if (cfg.ScreenLines == 25)
  98.         PushRadioButton(&Display, ID_25LINES);
  99.     else if (cfg.ScreenLines == 43)
  100.         PushRadioButton(&Display, ID_43LINES);
  101.     else if (cfg.ScreenLines == 50)
  102.         PushRadioButton(&Display, ID_50LINES);
  103.     if (SCREENHEIGHT != cfg.ScreenLines)    {
  104.         SetScreenHeight(cfg.ScreenLines);
  105.         if (WindowHeight(wnd) == ScreenHeight ||
  106.                 SCREENHEIGHT-1 < GetBottom(wnd))    {
  107.             WindowHeight(wnd) = SCREENHEIGHT-1;
  108.             GetBottom(wnd) = GetTop(wnd)+WindowHeight(wnd)-1;
  109.             wnd->RestoredRC = WindowRect(wnd);
  110.         }
  111.     }
  112.     SelectColors(wnd);
  113. #ifdef INCLUDE_WINDOWOPTIONS
  114.     SelectBorder(wnd);
  115.     SelectTitle(wnd);
  116.     SelectStatusBar(wnd);
  117. #endif
  118.     rtn = BaseWndProc(APPLICATION, wnd, CREATE_WINDOW, 0, 0);
  119.     if (wnd->extension != NULL)
  120.         CreateMenu(wnd);
  121.     CreateStatusBar(wnd);
  122.     LoadHelpFile();
  123.     SendMessage(NULL, SHOW_MOUSE, 0, 0);
  124.     return rtn;
  125. }
  126.  
  127. /* --------- ADDSTATUS Message ---------- */
  128. static void AddStatusMsg(WINDOW wnd, PARAM p1)
  129. {
  130.     if (wnd->StatusBar != NULL)    {
  131.         if (p1 && *(char *)p1)
  132.             SendMessage(wnd->StatusBar, SETTEXT, p1, 0);
  133.         else 
  134.             SendMessage(wnd->StatusBar, CLEARTEXT, 0, 0);
  135.         SendMessage(wnd->StatusBar, PAINT, 0, 0);
  136.     }
  137. }
  138.  
  139. /* -------- SETFOCUS Message -------- */
  140. static void SetFocusMsg(WINDOW wnd, BOOL p1)
  141. {
  142.     if (p1)
  143.         SendMessage(inFocus, SETFOCUS, FALSE, 0);
  144.     /* --- remove window from list --- */
  145.     RemoveFocusWindow(wnd);
  146.     /* --- move window to end/beginning of list --- */
  147.     p1 ? AppendFocusWindow(wnd) : PrependFocusWindow(wnd);
  148.     inFocus = p1 ? wnd : NULL;
  149.     SendMessage(wnd, BORDER, 0, 0);
  150. }
  151.  
  152. /* ------- SIZE Message -------- */
  153. static void SizeMsg(WINDOW wnd, PARAM p1, PARAM p2)
  154. {
  155.     BOOL WasVisible;
  156.     WasVisible = isVisible(wnd);
  157.     if (WasVisible)
  158.         SendMessage(wnd, HIDE_WINDOW, 0, 0);
  159.     if (p1-GetLeft(wnd) < 30)
  160.         p1 = GetLeft(wnd) + 30;
  161.     BaseWndProc(APPLICATION, wnd, SIZE, p1, p2);
  162.     CreateMenu(wnd);
  163.     CreateStatusBar(wnd);
  164.     if (WasVisible)
  165.         SendMessage(wnd, SHOW_WINDOW, 0, 0);
  166. }
  167.  
  168. /* ----------- KEYBOARD Message ------------ */
  169. static int KeyboardMsg(WINDOW wnd, PARAM p1, PARAM p2)
  170. {
  171.     AltDown = FALSE;
  172.     if (WindowMoving || WindowSizing || (int) p1 == F1)
  173.         return BaseWndProc(APPLICATION, wnd, KEYBOARD, p1, p2);
  174.     switch ((int) p1)    {
  175.         case ALT_F4:
  176.             PostMessage(wnd, CLOSE_WINDOW, 0, 0);
  177.             return TRUE;
  178. #ifdef INCLUDE_MULTI_WINDOWS
  179.         case ALT_F6:
  180.             SetNextFocus(inFocus);
  181.             SkipSystemWindows(FALSE);
  182.             return TRUE;
  183. #endif
  184.         case ALT_HYPHEN:
  185.             BuildSystemMenu(wnd);
  186.             return TRUE;
  187.         default:
  188.             break;
  189.     }
  190.     PostMessage(wnd->MenuBarWnd, KEYBOARD, p1, p2);
  191.     return TRUE;
  192. }
  193.  
  194. /* --------- SHIFT_CHANGED Message -------- */
  195. static void ShiftChangedMsg(WINDOW wnd, PARAM p1)
  196. {
  197.     if ((int)p1 & ALTKEY)
  198.         AltDown = TRUE;
  199.     else if (AltDown)    {
  200.         AltDown = FALSE;
  201.         if (wnd->MenuBarWnd != inFocus)
  202.             SendMessage(NULL, HIDE_CURSOR, 0, 0);
  203.         SendMessage(wnd->MenuBarWnd, KEYBOARD, F10, 0);
  204.     }
  205. }
  206.  
  207. /* -------- COMMAND Message ------- */
  208. static void CommandMsg(WINDOW wnd, PARAM p1, PARAM p2)
  209. {
  210.     switch ((int)p1)    {
  211.         case ID_HELP:
  212.             DisplayHelp(wnd, DFlatApplication);
  213.             break;
  214.         case ID_HELPHELP:
  215.             DisplayHelp(wnd, "HelpHelp");
  216.             break;
  217.         case ID_EXTHELP:
  218.             DisplayHelp(wnd, "ExtHelp");
  219.             break;
  220.         case ID_KEYSHELP:
  221.             DisplayHelp(wnd, "KeysHelp");
  222.             break;
  223.         case ID_HELPINDEX:
  224.             DisplayHelp(wnd, "HelpIndex");
  225.             break;
  226. #ifdef TESTING_DFLAT
  227.         case ID_LOADHELP:
  228.             LoadHelpFile();
  229.             break;
  230. #endif
  231. #ifdef INCLUDE_LOGGING
  232.         case ID_LOG:
  233.             MessageLog(wnd);
  234.             break;
  235. #endif
  236. #ifdef INCLUDE_SHELLDOS
  237.         case ID_DOS:
  238.             ShellDOS(wnd);
  239.             break;
  240. #endif
  241.         case ID_EXIT:
  242.         case ID_SYSCLOSE:
  243.             PostMessage(wnd, CLOSE_WINDOW, 0, 0);
  244.             break;
  245.         case ID_DISPLAY:
  246.             if (DialogBox(wnd, &Display, TRUE, NULL))    {
  247.                 SendMessage(wnd, HIDE_WINDOW, 0, 0);
  248.                 SelectColors(wnd);
  249.                 SelectLines(wnd);
  250. #ifdef INCLUDE_WINDOWOPTIONS
  251.                 SelectBorder(wnd);
  252.                 SelectTitle(wnd);
  253.                 SelectStatusBar(wnd);
  254.                 SelectTexture();
  255. #endif
  256.                 CreateMenu(wnd);
  257.                 CreateStatusBar(wnd);
  258.                 SendMessage(wnd, SHOW_WINDOW, 0, 0);
  259.             }
  260.             break;
  261.         case ID_SAVEOPTIONS:
  262.             SaveConfig();
  263.             break;
  264. #ifdef INCLUDE_MULTI_WINDOWS
  265.         case ID_WINDOW:
  266.             ChooseWindow(wnd, (int)p2-2);
  267.             break;
  268.         case ID_CLOSEALL:
  269.             CloseAll(wnd, FALSE);
  270.             break;
  271.         case ID_MOREWINDOWS:
  272.             MoreWindows(wnd);
  273.             break;
  274. #endif
  275. #ifdef INCLUDE_RESTORE
  276.         case ID_SYSRESTORE:
  277. #endif
  278.         case ID_SYSMOVE:
  279.         case ID_SYSSIZE:
  280. #ifdef INCLUDE_MINIMIZE
  281.         case ID_SYSMINIMIZE:
  282. #endif
  283. #ifdef INCLUDE_MAXIMIZE
  284.         case ID_SYSMAXIMIZE:
  285. #endif
  286.             BaseWndProc(APPLICATION, wnd, COMMAND, p1, p2);
  287.             break;
  288.         default:
  289.             if (inFocus != wnd->MenuBarWnd && inFocus != wnd)
  290.                 PostMessage(inFocus, COMMAND, p1, p2);
  291.             break;
  292.     }
  293. }
  294.  
  295. /* --------- CLOSE_WINDOW Message -------- */
  296. static int CloseWindowMsg(WINDOW wnd)
  297. {
  298.     int rtn;
  299. #ifdef INCLUDE_MULTI_WINDOWS
  300.     CloseAll(wnd, TRUE);
  301. #endif
  302.     PostMessage(NULL, STOP, 0, 0);
  303.     rtn = BaseWndProc(APPLICATION, wnd, CLOSE_WINDOW, 0, 0);
  304.     if (ScreenHeight != SCREENHEIGHT)
  305.         SetScreenHeight(ScreenHeight);
  306.     UnLoadHelpFile();
  307.     return rtn;
  308. }
  309.  
  310. /* --- APPLICATION Window Class window processing module --- */
  311. int ApplicationProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  312. {
  313.     switch (msg)    {
  314.         case CREATE_WINDOW:
  315.             return CreateWindowMsg(wnd);
  316.         case HIDE_WINDOW:
  317.             if (wnd == inFocus)
  318.                 inFocus = NULL;
  319.             break;
  320.         case ADDSTATUS:
  321.             AddStatusMsg(wnd, p1);
  322.             return TRUE;
  323.         case SETFOCUS:
  324.             if ((int)p1 == (inFocus != wnd))    {
  325.                 SetFocusMsg(wnd, (BOOL) p1);
  326.                 return TRUE;
  327.             }
  328.             break;
  329.         case SIZE:
  330.             SizeMsg(wnd, p1, p2);
  331.             return TRUE;
  332. #ifdef INCLUDE_MINIMIZE
  333.         case MINIMIZE:
  334.             return TRUE;
  335. #endif
  336.         case KEYBOARD:
  337.             return KeyboardMsg(wnd, p1, p2);
  338.         case SHIFT_CHANGED:
  339.             ShiftChangedMsg(wnd, p1);
  340.             return TRUE;
  341.         case PAINT:
  342.             if (isVisible(wnd))    {
  343. #ifdef INCLUDE_WINDOWOPTIONS
  344.                 int cl = cfg.Texture ? APPLCHAR : ' ';
  345. #else
  346.                 int cl = APPLCHAR;
  347. #endif
  348.                 ClearWindow(wnd, (RECT *)p1, cl);
  349.             }
  350.             return TRUE;
  351.         case COMMAND:
  352.             CommandMsg(wnd, p1, p2);
  353.             return TRUE;
  354.         case CLOSE_WINDOW:
  355.             return CloseWindowMsg(wnd);
  356.         default:
  357.             break;
  358.     }
  359.     return BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  360. }
  361.  
  362. #ifdef INCLUDE_SHELLDOS
  363. static void SwitchCursor(void)
  364. {
  365.     SendMessage(NULL, SAVE_CURSOR, 0, 0);
  366.     SwapCursorStack();
  367.     SendMessage(NULL, RESTORE_CURSOR, 0, 0);
  368. }
  369.  
  370. /* ------- Shell out to DOS ---------- */
  371. static void ShellDOS(WINDOW wnd)
  372. {
  373.     SendMessage(wnd, HIDE_WINDOW, 0, 0);
  374.     SwitchCursor();
  375.     if (ScreenHeight != SCREENHEIGHT)
  376.         SetScreenHeight(ScreenHeight);
  377.     SendMessage(NULL, HIDE_MOUSE, 0, 0);
  378.     printf("To return to %s, execute the DOS exit command.",
  379.                     DFlatApplication);
  380.     fflush(stdout);
  381.     spawnl(P_WAIT, getenv("COMSPEC"), NULL);
  382.     if (SCREENHEIGHT != cfg.ScreenLines)
  383.         SetScreenHeight(cfg.ScreenLines);
  384.     SwitchCursor();
  385.     SendMessage(wnd, SHOW_WINDOW, 0, 0);
  386.     SendMessage(NULL, SHOW_MOUSE, 0, 0);
  387. }
  388. #endif
  389.  
  390. /* -------- Create the menu bar -------- */
  391. static void CreateMenu(WINDOW wnd)
  392. {
  393.     AddAttribute(wnd, HASMENUBAR);
  394.     if (wnd->MenuBarWnd != NULL)
  395.         SendMessage(wnd->MenuBarWnd, CLOSE_WINDOW, 0, 0);
  396.     wnd->MenuBarWnd = CreateWindow(MENUBAR,
  397.                         NULL,
  398.                         GetClientLeft(wnd),
  399.                         GetClientTop(wnd)-1,
  400.                         1,
  401.                         ClientWidth(wnd),
  402.                         NULL,
  403.                         wnd,
  404.                         NULL,
  405.                         0);
  406.     SendMessage(wnd->MenuBarWnd,BUILDMENU,
  407.         (PARAM)wnd->extension,0);
  408.     AddAttribute(wnd->MenuBarWnd, VISIBLE);
  409. }
  410.  
  411. /* ----------- Create the status bar ------------- */
  412. static void CreateStatusBar(WINDOW wnd)
  413. {
  414.     if (wnd->StatusBar != NULL)    {
  415.         SendMessage(wnd->StatusBar, CLOSE_WINDOW, 0, 0);
  416.         wnd->StatusBar = NULL;
  417.     }
  418.     if (TestAttribute(wnd, HASSTATUSBAR))    {
  419.         wnd->StatusBar = CreateWindow(STATUSBAR,
  420.                             NULL,
  421.                             GetClientLeft(wnd),
  422.                             GetBottom(wnd),
  423.                             1,
  424.                             ClientWidth(wnd),
  425.                             NULL,
  426.                             wnd,
  427.                             NULL,
  428.                             0);
  429.         AddAttribute(wnd->StatusBar, VISIBLE);
  430.     }
  431. }
  432.  
  433. #ifdef INCLUDE_MULTI_WINDOWS
  434. /* -------- return the name of a document window ------- */
  435. static char *WindowName(WINDOW wnd)
  436. {
  437.     if (GetTitle(wnd) == NULL)    {
  438.         if (GetClass(wnd) == DIALOG)
  439.             return ((DBOX *)(wnd->extension))->HelpName;
  440.         else 
  441.             return "Untitled";
  442.     }
  443.     else
  444.         return GetTitle(wnd);
  445. }
  446.  
  447. /* ----------- Prepare the Window menu ------------ */
  448. void PrepWindowMenu(void *w, struct Menu *mnu)
  449. {
  450.     WINDOW wnd = w;
  451.     struct PopDown *p0 = mnu->Selections;
  452.     struct PopDown *pd = mnu->Selections + 2;
  453.     struct PopDown *ca = mnu->Selections + 13;
  454.     int MenuNo = 0;
  455.     WINDOW cwnd;
  456.     mnu->Selection = 0;
  457.     oldFocus = NULL;
  458.     if (GetClass(wnd) != APPLICATION)    {
  459.         int i;
  460.         oldFocus = wnd;
  461.         /* ----- point to the APPLICATION window ----- */
  462.         while (GetClass(wnd) != APPLICATION)
  463.             if ((wnd = GetParent(wnd)) == NULL)
  464.                 return;
  465.         /* ----- get the first 9 document windows ----- */
  466.         for (i = 0; i < wnd->ChildCt && MenuNo < 9; i++)    {
  467.             cwnd = *(wnd->Children + i);
  468.             if (GetClass(cwnd) != MENUBAR &&
  469.                     GetClass(cwnd) != STATUSBAR) {
  470.                 /* --- add the document window to the menu --- */
  471.                 strncpy(Menus[MenuNo]+4, WindowName(cwnd), 20);
  472.                 pd->SelectionTitle = Menus[MenuNo];
  473.                 if (cwnd == oldFocus)    {
  474.                     /* -- mark the current document -- */
  475.                     pd->Attrib |= CHECKED;
  476.                     mnu->Selection = MenuNo+2;
  477.                 }
  478.                 else
  479.                     pd->Attrib &= ~CHECKED;
  480.                 pd++;
  481.                 MenuNo++;
  482.             }
  483.         }
  484.     }
  485.     if (MenuNo)
  486.         p0->SelectionTitle = "~Close all";
  487.     else
  488.         p0->SelectionTitle = NULL;
  489.     if (MenuNo >= 9)    {
  490.         *pd++ = *ca;
  491.         if (mnu->Selection == 0)
  492.             mnu->Selection = 11;
  493.     }
  494.     pd->SelectionTitle = NULL;
  495. }
  496.  
  497. /* window processing module for the More Windows dialog box */
  498. static int WindowPrep(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
  499. {
  500.     switch (msg)    {
  501.         case INITIATE_DIALOG:    {
  502.             WINDOW wnd1;
  503.             WINDOW cwnd = ControlWindow(&Windows,ID_WINDOWLIST);
  504.             WINDOW pwnd = GetParent(wnd);
  505.             int sel = 0, i;
  506.             if (cwnd == NULL)
  507.                 return FALSE;
  508.             for (i = 0; i < pwnd->ChildCt; i++)    {
  509.                 wnd1 = *(pwnd->Children + i);
  510.                 if (wnd1 != wnd && GetClass(wnd1) != MENUBAR &&
  511.                         GetClass(wnd1) != STATUSBAR)    {
  512.                     if (wnd1 == oldFocus)
  513.                         WindowSel = sel;
  514.                     SendMessage(cwnd, ADDTEXT,
  515.                         (PARAM) WindowName(wnd1), 0);
  516.                     sel++;
  517.                 }
  518.             }
  519.             SendMessage(cwnd, LB_SETSELECTION, WindowSel, 0);
  520.             AddAttribute(cwnd, VSCROLLBAR);
  521.             PostMessage(cwnd, SHOW_WINDOW, 0, 0);
  522.             break;
  523.         }
  524.         case COMMAND:
  525.             switch ((int) p1)    {
  526.                 case ID_OK:
  527.                     if ((int)p2 == 0)
  528.                         WindowSel = SendMessage(
  529.                                     ControlWindow(&Windows,
  530.                                     ID_WINDOWLIST),
  531.                                     LB_CURRENTSELECTION, 0, 0);
  532.                     break;
  533.                 case ID_WINDOWLIST:
  534.                     if ((int) p2 == LB_CHOOSE)
  535.                         SendMessage(wnd, COMMAND, ID_OK, 0);
  536.                     break;
  537.                 default:
  538.                     break;
  539.             }
  540.             break;
  541.         default:
  542.             break;
  543.     }
  544.     return DefaultWndProc(wnd, msg, p1, p2);
  545. }
  546.  
  547. /* ---- the More Windows command on the Window menu ---- */
  548. static void MoreWindows(WINDOW wnd)
  549. {
  550.     if (DialogBox(wnd, &Windows, TRUE, WindowPrep))
  551.         ChooseWindow(wnd, WindowSel);
  552. }
  553.  
  554. /* ----- user chose a window from the Window menu
  555.         or the More Window dialog box ----- */
  556. static void ChooseWindow(WINDOW wnd, int WindowNo)
  557. {
  558.     int i;
  559.     WINDOW cwnd;
  560.     for (i = 0; i < wnd->ChildCt; i++)    {
  561.         cwnd = *(wnd->Children + i);
  562.         if (GetClass(cwnd) != MENUBAR &&
  563.                 GetClass(cwnd) != STATUSBAR)
  564.             if (WindowNo-- == 0)
  565.                 break;
  566.     }
  567.     if (wnd->ChildCt)    {
  568.         SendMessage(cwnd, SETFOCUS, TRUE, 0);
  569.         if (cwnd->condition == ISMINIMIZED)
  570.             SendMessage(cwnd, RESTORE, 0, 0);
  571.     }
  572. }
  573.  
  574. /* ----- Close all document windows ----- */
  575. static void CloseAll(WINDOW wnd, int closing)
  576. {
  577.     WINDOW wnd1;
  578.     int i;
  579.     SendMessage(wnd, SETFOCUS, TRUE, 0);
  580.     for (i = wnd->ChildCt; i > 0; --i)    {
  581.         wnd1 = *(wnd->Children + i - 1);
  582.         if (GetClass(wnd1) != MENUBAR &&
  583.                 GetClass(wnd1) != STATUSBAR)    {
  584.             ClearVisible(wnd1);
  585.             SendMessage(wnd1, CLOSE_WINDOW, 0, 0);
  586.         }
  587.     }
  588.     if (!closing)
  589.         SendMessage(wnd, PAINT, 0, 0);
  590. }
  591.  
  592. #endif    /* #ifdef INCLUDE_MULTI_WINDOWS */
  593.  
  594. static void DoWindowColors(WINDOW wnd)
  595. {
  596.     WINDOW cwnd;
  597.     int i;
  598.     InitWindowColors(wnd);
  599.     for (i = 0; i < wnd->ChildCt; i++)    {
  600.         cwnd = *(wnd->Children + i);
  601.         InitWindowColors(cwnd);
  602.         if (GetClass(cwnd) == TEXT && GetText(cwnd) != NULL)
  603.             SendMessage(cwnd, CLEARTEXT, 0, 0);
  604.     }
  605. }
  606.  
  607. /* ----- set up colors for the application window ------ */
  608. static void SelectColors(WINDOW wnd)
  609. {
  610.     if (RadioButtonSetting(&Display, ID_MONO))
  611.         cfg.mono = 1;
  612.     else if (RadioButtonSetting(&Display, ID_REVERSE))
  613.         cfg.mono = 2;
  614.     else
  615.         cfg.mono = 0;
  616.     if ((ismono() || video_mode == 2) && cfg.mono == 0)
  617.         cfg.mono = 1;
  618.  
  619.     if (cfg.mono == 1)
  620.         memcpy(cfg.clr, bw, sizeof bw);
  621.     else if (cfg.mono == 2)
  622.         memcpy(cfg.clr, reverse, sizeof reverse);
  623.     else
  624.         memcpy(cfg.clr, color, sizeof color);
  625.     DoWindowColors(wnd);
  626. }
  627.  
  628. /* ---- select screen lines ---- */
  629. static void SelectLines(WINDOW wnd)
  630. {
  631.     cfg.ScreenLines = 25;
  632.     if (isEGA() || isVGA())    {
  633.         if (RadioButtonSetting(&Display, ID_43LINES))
  634.             cfg.ScreenLines = 43;
  635.         else if (RadioButtonSetting(&Display, ID_50LINES))
  636.             cfg.ScreenLines = 50;
  637.     }
  638.     if (SCREENHEIGHT != cfg.ScreenLines)    {
  639.         int FullScreen = WindowHeight(wnd) == SCREENHEIGHT;
  640.         SetScreenHeight(cfg.ScreenLines);
  641.         if (FullScreen || SCREENHEIGHT-1 < GetBottom(wnd))
  642.             SendMessage(wnd, SIZE, (PARAM) GetRight(wnd),
  643.                 SCREENHEIGHT-1);
  644.     }
  645. }
  646.  
  647. /* ---- set the screen height in the video hardware ---- */
  648. static void SetScreenHeight(int height)
  649. {
  650.     if (isEGA() || isVGA())    {
  651.         SendMessage(NULL, SAVE_CURSOR, 0, 0);
  652.         switch (height)    {
  653.             case 25:
  654.                 Set25();
  655.                 break;
  656.             case 43:
  657.                 Set43();
  658.                 break;
  659.             case 50:
  660.                 Set50();
  661.                 break;
  662.             default:
  663.                 break;
  664.         }
  665.         SendMessage(NULL, RESTORE_CURSOR, 0, 0);
  666.         SendMessage(NULL, RESET_MOUSE, 0, 0);
  667.         SendMessage(NULL, SHOW_MOUSE, 0, 0);
  668.     }
  669. }
  670.  
  671. #ifdef INCLUDE_WINDOWOPTIONS
  672.  
  673. /* ----- select the screen texture ----- */
  674. static void SelectTexture(void)
  675. {
  676.     cfg.Texture = CheckBoxSetting(&Display, ID_TEXTURE);
  677. }
  678.  
  679. /* -- select whether the application screen has a border -- */
  680. static void SelectBorder(WINDOW wnd)
  681. {
  682.     cfg.Border = CheckBoxSetting(&Display, ID_BORDER);
  683.     if (cfg.Border)
  684.         AddAttribute(wnd, HASBORDER);
  685.     else
  686.         ClearAttribute(wnd, HASBORDER);
  687. }
  688.  
  689. /* select whether the application screen has a status bar */
  690. static void SelectStatusBar(WINDOW wnd)
  691. {
  692.     cfg.StatusBar = CheckBoxSetting(&Display, ID_STATUSBAR);
  693.     if (cfg.StatusBar)
  694.         AddAttribute(wnd, HASSTATUSBAR);
  695.     else
  696.         ClearAttribute(wnd, HASSTATUSBAR);
  697. }
  698.  
  699. /* select whether the application screen has a title bar */
  700. static void SelectTitle(WINDOW wnd)
  701. {
  702.     cfg.Title = CheckBoxSetting(&Display, ID_TITLE);
  703.     if (cfg.Title)
  704.         AddAttribute(wnd, HASTITLEBAR);
  705.     else
  706.         ClearAttribute(wnd, HASTITLEBAR);
  707. }
  708.  
  709. #endif
  710.  
  711.  
  712.  
  713.